<template>
	<view class="page">
		
		<u-tabs :list="nav" :current="current" @change="change"  bg-color="#F1F1F1"></u-tabs>
	
		
		<view v-for="(item,index) in list" :key="index" class="u-border-bottom list" @click="go(item)">
			<view class="u-flex u-row-between $u-type-info u-font-sm">
				<view>订单号{{item.outTradeNo}}</view>
				<view>{{item.status==1?'待支付':item.status==2?'待核销':item.status==3?'已核销':item.status==4?'已完成':''}}</view>
			</view>
			<view class="u-flex u-margin-top-20" v-for="(item1,index1) in item.goods" :key="index1">
				<u-image :src="item1.cover" width="100" height="100"></u-image>
				<view class="u-margin-left-20  ">
					<view>{{item1.goodsName}}</view>
					<view style="font-size: 28rpx;" class="$u-type-info"><text
							style="color: #FA3534;">￥{{item1.price}}</text></view>
				</view>

			</view>

			<view style="display: flex;justify-content: flex-end;">
				<view class="btn" @click.stop="btncontrols(item)"  v-if="item.status!==3">
					{{item.status==1&& !item.state?'立即支付':''}}
					{{item.status==2 || item.status==4 && !item.state?'查看详情':''}}
				</view>
				<view class="btn u-margin-left-20" style="background: #F0AD4E;"  v-else @click.stop="btncontrols(item)" >
					评价
				</view>
			</view>
			
		</view>
		
		<u-loadmore :status="status"  />
	</view>
</template>

<script>
	import loader from '@/common/loadPage.js';
	import payway from '@/common/wxpay.js';
	export default {
		mixins: [loader],
		data() {

			return {
				nav: [{
						name: '全部',
						id:0
				},{
						name: '待支付',
						id:1
				},{
						name: '待核销',
						id:2
				},{
						name: '已核销',
						id:3
				},{
						name: '已完成',
						id:4
				}],
				current: 0,
				list: [],
				initial: {
					geturl: "/api/indent/orderList",
					parm: {
						state: 0,
						order_type:3
					},
					isPage: true
				},





			}
		},
		async onLoad() {

			
		},
		onShow() {
			this.getGoods()
		},
		methods: {
			change(e){
				this.current=e;
				this.initial.page=1;
				this.initial.parm.state=this.nav[e].id;
				this.getGoods()
			},
			go(item) {
				uni.navigateTo({
					url: './goodsDetail?id=' + item.id
				})
			},
			btncontrols(item) {
				// 支付
				if (item.status == 1) {
					this.$u.post('/api/indent/pay', {
						order_id: item.id
					}, {}).then(res => {
						var packages = res.data.package;
						var {
							noncestr,
							timestamp,
							signtype,
							paysign
						} = res.data;
						payway.wx(timestamp, noncestr, packages, signtype, paysign).then(res => {
							this.$refs.uToast.show({
								title: '支付成功',
								type: 'success',
								back: true,
							})
							this.page = 1;
							this.getBook()
						}).catch(err => {
							console.log(res)
						})

					}).catch(err => {})
				}
				// 查看详情 已完成
				if (item.status == 2 || item.status == 4) {

					uni.navigateTo({
						url: "./goodsDetail?id=" + item.id
					})
				}
				
				if(item.status==3){
					uni.navigateTo({
						url:"./comment?id="+item.id
					})
				}
				


			},

		}
	}
</script>


<style>
	.page {
		background: #F1F1F1;
		min-height: 100vh;
		width: 100%;
		display: inline-block;
	}

	.list {
		background: #fff;
		width: 700rpx;
		margin: 20rpx auto;
		padding: 20rpx;
	}

	.btn {
		width: 140rpx;
		height: 50rpx;
		background: #608CFF;
		border-radius: 40rpx;
		text-align: center;
		line-height: 50rpx;
		font-size: 24rpx;
		color: #FFFFFF;

	}
</style>
